<template>
  <div class="zhengti">

    <!--搜索条件-->
    <div class="boxone">
      <el-form :inline="true">

        <el-form-item label="日期:" label-width="50px">
          <el-date-picker
            v-model="startTime"
            style="width:70%"
            type="date"
            placeholder="起始日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="~" label-width="50px" style="margin-left: -5.5%">
          <el-date-picker
            v-model="endTime"
            style="width:70%"
            type="date"
            placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item style="float:right">
          <el-button type="primary" size="small" @click="handleSearch">搜索</el-button>
          <el-button size="small" @click="reset">重置</el-button>
          <el-button type="success" size="small" @click="handleExport">导出</el-button>
        </el-form-item>

      </el-form>
    </div>

    <!--表格-->
    <div class="biao">
      <el-table :data="tableData" :loading="loading" border height="650" style="width: 100%" empty-text="玉泉宫">

        <el-table-column align="center" prop="type" label="卡类">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yqg_type" :value="scope.row.type"/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="cardNature" label="卡性质">
          <template slot-scope="scope">
            <div v-if="scope.row.cardNature==='999'">小计</div>
            <dict-tag :options="dict.type.yqg_card_nature" :value="scope.row.cardNature" v-else/>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="number" label="笔数"/>

        <el-table-column align="center" prop="netReceipts" label="实收"/>

        <el-table-column align="center" prop="cash" label="现金"/>

        <el-table-column align="center" prop="bankcard" label="信用卡"/>

        <el-table-column align="center" prop="zero" label=""/>

        <el-table-column align="center" prop="zero" label=""/>

        <el-table-column align="center" prop="zero" label=""/>

        <el-table-column align="center" prop="zero" label=""/>

        <el-table-column align="center" prop="zero" label=""/>

        <el-table-column align="center" prop="consumableAmount" label="可消费"/>

      </el-table>
    </div>
  </div>
</template>

<script>
import {sell} from "@/api/module/wtc/form"

export default {
  dicts: ['yqg_type', 'yqg_card_nature'],
  data() {
    return {
      /*起始日期选择器*/
      startTime: '',
      endTime: '',
      tableData: [],
      loading: false,
      // 会员表查询参数
      queryParams: {
        note1: null,
        note2: null
      },
    }
  },

  methods: {
    handleSearch() {
      if (this.startTime === '' || this.endTime === '' || this.startTime === null || this.endTime === null) {
        return
      }
      this.loading = true
      sell(this.startTime, this.endTime).then(res => {
        this.tableData = res.rows
        this.loading = false
      })
    },
    reset() {
      this.startTime = ''
      this.endTime = ''
      this.tableData = []
    },
    handleExport() {
      if (this.startTime === '' || this.endTime === '' || this.startTime === null || this.endTime === null) {
        return
      }
      let stime = new Date(this.startTime).getTime()
      let etime = new Date(this.endTime).getTime()
      this.queryParams.note1 = stime
      this.queryParams.note2 = etime
      this.download('project/wtc/form/export/sell', {
        ...this.queryParams
      }, `会员卡销售表_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>
.zhengti {
  display: flex;
  flex-direction: column;
  margin-left: 1%;
  margin-right: 1%;
  margin-bottom: 1%;
}

.boxone {
  margin-top: 2%;
  display: inline-block;
}

.biao {
  margin-top: 5px;
}
</style>
